#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void game()
{
	int num = rand() % 100 + 1;
	int guess = 0;
	while (1)
	{
		printf("请输入你猜的数1~100：");
		scanf("%d", &guess);
		if(guess < num)
		{
			printf("猜小了\n");
		}
		else if (guess > num)
		{
			printf("猜大了\n");
		}
		else
		{
			printf("恭喜你！猜对了\n");
			break;
		}
	}
}

int main()
{

	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		printf("猜数字游戏，输入1开始，输入0退出\n");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("您已退出\n");
			break;
		default:
			printf("输入错误，请重新输入！\n");
			break;
		}
	} while (input);
	return 0;
}